import os

env = Environment(LIBS = ['icudata', 'icui18n', 'icuuc', 'pthread'],
                  CPPPATH = './',
                  LIBPATH = './')


if 'GTEST_DIR' in os.environ:
  env.Append( CXXFLAGS = '-I ' + os.environ['GTEST_DIR'] + '/include' )

conf = Configure(env)

sources = [
  'url/gurl.cc',
  'url/third_party/mozilla/url_parse.cc',
  'url/url_canon_etc.cc',
  'url/url_canon_filesystemurl.cc',
  'url/url_canon_fileurl.cc',
  'url/url_canon_host.cc',
  'url/url_canon_icu.cc',
  'url/url_canon_internal.cc',
  'url/url_canon_ip.cc',
  'url/url_canon_mailtourl.cc',
  'url/url_canon_path.cc',
  'url/url_canon_pathurl.cc',
  'url/url_canon_query.cc',
  'url/url_canon_relative.cc',
  'url/url_canon_stdurl.cc',
  'url/url_parse_file.cc',
  'url/url_util.cc',

#  'base/strings/latin1_string_conversions.cc',
#  'base/strings/nullable_string16.cc',
#  'base/strings/nullable_string16_unittest.cc',
  'base/strings/string16.cc',
#  'base/strings/string16_unittest.cc',
#  'base/strings/stringize_macros_unittest.cc',


#  'base/strings/string_number_conversions.cc',
#  'base/strings/string_number_conversions_unittest.cc',
  'base/strings/string_piece.cc',
#  'base/strings/string_piece_unittest.cc',
#  'base/strings/stringprintf.cc',
#  'base/strings/stringprintf_unittest.cc',
#  'base/strings/string_split.cc',
#  'base/strings/string_split_unittest.cc',
#  'base/strings/string_tokenizer_unittest.cc',
  'base/strings/string_util.cc',
  'base/strings/string_util_constants.cc',
#  'base/strings/string_util_unittest.cc',
#  'base/strings/sys_string_conversions_posix.cc',
#  'base/strings/sys_string_conversions_unittest.cc',
##  'base/strings/sys_string_conversions_win.cc',
#  'base/strings/utf_offset_string_conversions.cc',
#  'base/strings/utf_offset_string_conversions_unittest.cc',
  'base/strings/utf_string_conversions.cc',
#  'base/strings/utf_string_conversions_unittest.cc',
  'base/strings/utf_string_conversion_utils.cc',

  'base/logging.cc',

  'base/third_party/icu/icu_utf.cc',
]

staticlib = env.StaticLibrary(target = 'chromium-url', source = sources)
Default(staticlib)

sharedlib = env.SharedLibrary(target = 'chromium-url', source = sources)
Default(sharedlib)

if 'test' in COMMAND_LINE_TARGETS:
  errors = False
  if not conf.CheckCXXHeader('gtest/gtest.h'):
    print 'Header gtest/gtest.h must be installed!'
    errors = True
  if not 'GTEST_DIR' in os.environ:
    print 'Environment variable GTEST_DIR must be defined!'
    errors = True
  if errors:
    Exit(1)

testsources = [
  'url/gurl_unittest.cc',
  'url/url_parse_unittest.cc',
  'url/url_canon_unittest.cc',
  'url/url_util_unittest.cc',
]
testobjects = [
  env.Object(testsources),
]

if 'GTEST_DIR' in os.environ:
  testobjects += [
    os.environ['GTEST_DIR'] + '/libgtest.a',
    os.environ['GTEST_DIR'] + '/libgtest_main.a',
    'libchromium-url.a'
  ]

env.Program('test', testobjects)
